/**********************************************************************
 * JSC(JavaScript Component): PopUp Support
 * Copyright (c) 2007 lenel(lenel@yahoo.cn)
 * JSC is freely distributable under the terms of an MIT-style license.
 * $Date: 2007-09
 **********************************************************************/

_jsc.popup = (function(){		
	var t = {};
	t.clk = {};
	t.clk.popSet = {}
	t.clk.show = function(oEvent,popid,ref,rx,ry){
		_jsc.popup.clk.hideAll();
		_jsc.popup.clk.popSet[popid].show(ref,rx,ry);
		try{
			oEvent.stopPropagation();
		}catch(e){
			oEvent.cancelBubble = true;
		}
	};
	t.clk.hide = function(popid,resValue){
		t.clk.popSet[popid].curValue = resValue;
		t.clk.popSet[popid].hide();
	};
	t.clk.enabled = false;
	t.clk.addPop = function(popObj){
		if(!t.clk.enabled){
			_jsc.util.addEvent(document.body,'click',_jsc.popup.clk.hideAll);
			t.clk.enabled = true;
		}
		t.clk.popSet[popObj.popId] = popObj;
	};
	t.clk.hideAll = function(){
		for(popid in t.clk.popSet){
			if(t.clk.popSet[popid].isShow == true){
				t.clk.popSet[popid].hide();
			}
		}
	};
	t.over = {};
	return t;
})();

function JscPopupClk(popupBody,resHandler,defValue){
	this.body = popupBody;
	this.popId = this.body.id;
	this.resHandler = resHandler;
	this.defValue = defValue;
	this.curValue = defValue;
	this.isShow = false;
	this.setCurValue = function(s){
		this.curValue = s;
	};
	this.show = function(ref,rx,ry){
		if(!rx)var rx = 0;
		if(!ry)var ry = 0;
		var l = _jsc.pos.getX(ref)+rx;
		var t = _jsc.pos.getY(ref)+parseInt(ref.offsetHeight)+ry;
		this.body.style.left = l+"px";
		this.body.style.top = t+"px";
		this.body.style.display = "";
		this.isShow = true;
	};
	this.hide = function(oEvent){
		this.body.style.display = "none";
		eval("var t = typeof "+resHandler);
		if(t == "function"){
			eval("resHandler(\""+this.curValue+"\");");
		}
		this.curValue = this.defValue;
		this.isShow = false;
	};
	_jsc.popup.clk.addPop(this);
}
